<?php

/**
 * Description of ItHappensParser
 *
 * @author pahhan
 */
class Model_Parser_BashQuotes_Parser extends Model_Parser
{
    public function getParseInfoId()
    {
        return 1;
    }

    public function getCharset()
    {
        return 'windows-1251';
    }

    public function getNextUrl($html)
    {
        return FALSE;
    }

    /**
     * @return Model_ParserResult
     */
    public function parseHtml($html)
    {
        if( $this->parse_result )
            return $this->parse_result;

        $crawler = $this->getCrawler($html);
        $quote = $crawler->filter('div.quote');
        if( $quote->count() === 0 ) return FALSE;

        $actions = $quote->filter('div.actions');
        if( $actions->count() === 0 ) return FALSE;

        $result = new Model_Parser_BashQuotes_ParserResult();

        $result->temp_id = $actions->filter('a.id')->text();
        $result->published_at = $actions->filter('span.date')->text();
        $result->content = $quote->filter('div.text')->html();

        $this->parse_result = $result;
        return $result;
    }

    public function validateHtml($html, $id)
    {
        $result = $this->parseHtml($html);
        if( !$result ) return FALSE;
        return $result->getExternalId() == $id;
    }

}